﻿#define _CRT_SECURE_NO_WARNINGS

#include "AVLTree.h"
#include <vector>


void TestAVLTree1()
{
    TL::AVLTree<int, int> t;

    //常规的测试⽤例
    //int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };

    //特殊的带有双旋场景的测试⽤例
    int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
    for (auto e : a)
    {
        t.insert({ e, e });
        //t.InOrder();

        //cout << t.IsBalance() << endl;

    }
    t.InOrder();
    cout << t.size() << endl;
    cout << t.height() << endl;
    cout << t.IsBalance() << endl;
    cout << t.find(3) << endl;
}

void TestAVLTree2()
{
    const int N = 100000;
    vector<int> v;
    v.reserve(N);
    srand((unsigned int)time(NULL));
    for (int i = 0; i < N; i++)
    {
        v.push_back(rand() + i);
    }
    size_t begin2 = clock();
    TL::AVLTree<int, int> t;
    for (auto e : v)
    {
        t.insert(pair<int,int>(e, e));
    }
    size_t end2 = clock();
    cout << "insert:" << end2 - begin2 << endl;
    cout << t.IsBalance() << endl;
    cout << "height:" << t.height() << endl;
    cout << "size:" << t.size() << endl;
    size_t begin1 = clock();
    // 确定在的值
    
    //随机值
    for (int i = 0; i < N; i++)
    {
        t.find((rand() + i));
    }
    size_t end1 = clock();
    cout << "find:" << end1 - begin1 << endl;
}

int main()
{
    TestAVLTree2();
	return 0;
}